/**************************************************************************
 * Copyright (C) 2020-2020  Unisound
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 **************************************************************************
 *
 * Description : user_gpio.c
 * Author      : yuanshifeng@unisound.com
 * Date        : 2020.04.24
 *
 **************************************************************************/
#include "uni_hal_adc.h"
#include "user_adc.h"

#define TAG "user_adc"

static uni_bool g_is_adc_init = false;

int user_adc_init(void)
{
  uni_hal_adc_init();
  g_is_adc_init = true;
  return 0;
}

int user_adc_get_value(ADC_AIN_SEL adc_ain, int *value)
{
  if (!g_is_adc_init) {
    LOGE(TAG, "have not init adc");
    return -1;
  }
  return uni_hal_adc_get_value(adc_ain, value);
}

int user_adc_start(void)
{
  if (!g_is_adc_init) {
    LOGE(TAG, "have not init adc");
    return -1;
  }
  uni_hal_adc_start();
  return 0;
}

int user_adc_final(void)
{
  uni_hal_adc_final();
  g_is_adc_init = false;
  return 0;
}

